export interface Operator {
  key: string; // 操作符标识
  name: string; // 操作符中文名称
  symbol?: string; // 操作符符号
}

export type OperatorObj = Record<string, Operator>;

export type TypeOperator = Record<string, string[]>;

// 操作符类型
export type OperatorType =
  | 'EQ'
  | 'NOT_EQ'
  | 'LIKE'
  | 'NOT_LIKE'
  | 'START_WITH'
  | 'END_WITH'
  | 'IN'
  | 'NOT_IN'
  | 'IS_NULL'
  | 'IS_NOT_NULL'
  | 'LT'
  | 'LT_EQ'
  | 'GT'
  | 'GT_EQ'
  | 'EMPTY';

const ALL_OPERATORS: OperatorObj = {
  EQ: {
    key: 'EQ',
    symbol: '=',
    name: '等于',
  },
  NOT_EQ: {
    key: 'NOT_EQ',
    symbol: '!=',
    name: '不等于',
  },
  LIKE: {
    key: 'LIKE',
    symbol: '包含',
    name: '包含',
  },
  NOT_LIKE: {
    key: 'NOT_LIKE',
    symbol: '不包含',
    name: '不包含',
  },
  START_WITH: {
    key: 'START_WITH',
    symbol: '以..开头',
    name: '以..开头',
  },
  END_WITH: {
    key: 'END_WITH',
    symbol: '以..结尾',
    name: '以..结尾',
  },
  IN: {
    key: 'IN',
    symbol: '属于',
    name: '属于',
  },
  NOT_IN: {
    key: 'NOT_IN',
    symbol: '不属于',
    name: '不属于',
  },
  IS_NULL: {
    key: 'IS_NULL',
    symbol: '为空',
    name: '为空',
  },
  IS_NOT_NULL: {
    key: 'IS_NOT_NULL',
    symbol: '不为空',
    name: '不为空',
  },
  LT: {
    key: 'LT',
    name: '小于',
    symbol: '<',
  },
  LT_EQ: {
    key: 'LT_EQ',
    name: '小于等于',
    symbol: '<=',
  },
  GT: {
    key: 'GT',
    name: '大于',
    symbol: '>',
  },
  GT_EQ: {
    key: 'GT_EQ',
    name: '大于等于',
    symbol: '>=',
  },
  EMPTY: {
    key: 'EMPTY',
    symbol: '无',
    name: '无',
  },
};

// 类型与操作符对应
const TYPE_OPERATORS: TypeOperator = {
  string: ['EQ', 'NOT_EQ', 'LIKE', 'NOT_LIKE', 'START_WITH', 'END_WITH', 'IN', 'NOT_IN', 'IS_NULL', 'IS_NOT_NULL'],
  number: ['EQ', 'NOT_EQ', 'LT', 'LT_EQ', 'GT', 'GT_EQ', 'IN', 'NOT_IN', 'IS_NULL', 'IS_NOT_NULL'],
  date: ['EQ', 'NOT_EQ', 'LT', 'LT_EQ', 'GT', 'GT_EQ', 'IS_NULL', 'IS_NOT_NULL'],
  boolean: ['EQ', 'IS_NULL', 'IS_NOT_NULL'],
  codelist: ['EQ', 'IN', 'NOT_IN', 'IS_NULL', 'IS_NOT_NULL'],
  object: ['EQ', 'IN', 'NOT_IN', 'IS_NULL', 'IS_NOT_NULL'],
};

export { ALL_OPERATORS as allOperators, TYPE_OPERATORS as typeOperators };
